package net.sxnic.ugr.menu.action;

import net.sxinfo.core.dao.Page;
import net.sxinfo.core.dao.hibernate3.HibernateCriteria;
import net.sxinfo.core.dao.hibernate3.HibernateDaoUtils;
import net.sxinfo.core.dao.hibernate3.HibernateOrder;
import net.sxinfo.core.util.WebUtils;
import net.sxnic.comm.utils.PropertyUtil;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;

public class Browse extends MenuAction {

	private static final long serialVersionUID = 1L;

	private static Log log = LogFactory.getLog(Browse.class);

	private Page menus;
	private String queryMenuCode="";
	private String queryMenuName="";

	public String execute() throws Exception {
		try {						
			int pageNumber = WebUtils.getPageNumber(request);
		    int pageSize = PropertyUtil.findTableSize("firstbrowse.tabsize");	
		    
		    HibernateOrder infoCodeOrder = HibernateDaoUtils.createHibernateOrder(
					"menuOrder", true);
			HibernateCriteria hc = new HibernateCriteria().add(infoCodeOrder);

			Criterion dc = null;
			// 组合条件
			if (StringUtils.isNotBlank(queryMenuCode)) {//登录名
				dc = Restrictions.like("code", "%" + queryMenuCode + "%");
				hc.add(dc);
			}
			if (StringUtils.isNotBlank(queryMenuName)) {//用户名
				dc = Restrictions.like("value", "%" + queryMenuName + "%");
				hc.add(dc);
			}
			menus = menuManager.getPageByCriteria(pageNumber, pageSize, hc);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}

	public Page getMenus() {
		return this.menus;
	}

	public void setMenus(Page menus) {
		this.menus = menus;
	}

	public String getQueryMenuCode() {
		return queryMenuCode;
	}

	public void setQueryMenuCode(String queryMenuCode) {
		this.queryMenuCode = queryMenuCode;
	}

	public String getQueryMenuName() {
		return queryMenuName;
	}

	public void setQueryMenuName(String queryMenuName) {
		this.queryMenuName = queryMenuName;
	}
}
